<template>
  <div>
    <el-button :icon="Plus" type="primary" @click="isShowSpuInfoList = false"
      >添加SPU</el-button
    >
    <el-table border style="margin: 20px 0">
      <el-table-column
        label="序号"
        type="index"
        align="center"
        width="80px"
      ></el-table-column>
      <el-table-column label="SPU名称"></el-table-column>
      <el-table-column label="SPU描述"></el-table-column>
      <el-table-column label="操作">
        <el-button size="small" title="添加SKU" :icon="Plus"></el-button>
        <el-button size="small" title="修改SPU" :icon="Edit"></el-button>
        <el-button
          size="small"
          title="查看SKU列表"
          :icon="InfoFilled"
        ></el-button>
        <el-button size="small" title="删除SPU" :icon="Delete"></el-button>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      v-model:currentPage="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[3, 6, 9, 12]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout=" prev, pager, next, jumper,->, sizes,total"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script lang="ts">
export default {
  name: "SpuList",
};
</script>
<script lang="ts" setup>
//1.引入接口函数
import { getSpuListData } from "@/api/product/spu";
//引入仓库
import {useCategoryListStore} from '@/stores/categoryList'
//引入组件模块
import { Plus, Edit, Delete, InfoFilled } from "@element-plus/icons-vue";
import { ref, watch } from "vue";
const small = ref(false);
const background = ref(false);
const disabled = ref(false);
const isShowSpuInfoList = ref(true)
// 分页相关的变量
const currentPage = ref <number> (1);
const pageSize = ref <number> (3);
const total = ref <number> (1);
const spuList = ref([]);
//2.获取数据
//先获取仓库
const categoryStore = useCategoryListStore()
const getSpuListDataInfo = async ()=>{
  const res = await getSpuListData(currentPage.value,pageSize.value,categoryStore.category3ID)
  spuList.value = res.records
  total.value = res.total
}
//3.渲染数据

// 4. 每页显示多少条触发的时候，也要重新渲染页面
const handleSizeChange = (val: number) => {
  // console.log(`${val} items per page`);
  pageSize.value = val;
  currentPage.value = 1; // 重置为1

  getSpuListDataInfo();
};

// 3. 页码发生变化的时候 重新发送请求
const handleCurrentChange = (val: number) => {
  // console.log(`current page: ${val}`);
  currentPage.value = val;
  getSpuListDataInfo();
};
</script>
<style></style>
